﻿package mortal.game.view.heroArena.view
{
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.heroArena.renderer.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class HeroArenaTeamGroupWin extends BaseWindow
    {
        private var _refreshBtn:GButton;
        private var _pageSelecter:PageSelecter;
        private var _closeWinBtn:GButton;
        private var _infoList:GTileList;
        private static var _instance:HeroArenaTeamGroupWin;

        public function HeroArenaTeamGroupWin(param1:ILayer = null)
        {
            super(param1);
            setSize(421, 387);
            title = Language.getString(41626);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(10, 38, 405, 302, this));
            this.pushUIToDisposeVec(UIFactory.bg(10, 39, 405, 23, this, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41627), 25, 45 - 5, 95, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41628), 147, 45 - 5, 64, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41629), 235, 45 - 5, 98, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41630), 364, 45 - 5, 45, 20, this));
            this._infoList = UIFactory.tileList(10, 61, 410, 254, this.contentTopOf3DSprite);
            this._infoList.columnWidth = 403;
            this._infoList.rowHeight = 49;
            this._infoList.horizontalGap = 0;
            this._infoList.verticalGap = 0;
            this._infoList.setStyle("skin", new Bitmap());
            this._infoList.setStyle("cellRenderer", HeroArenaGroupListCellRenderer);
            this._refreshBtn = UIFactory.gButton(Language.getString(41631), 28, 310, 63, 21, this);
            this._refreshBtn.configEventListener(MouseEvent.CLICK, this.onRefreshHandler);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(145, 309, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._closeWinBtn = UIFactory.gButton(Language.getString(41632), 182 + 3, 353, 60 + 3, 19 + 3, this);
            this._closeWinBtn.configEventListener(MouseEvent.CLICK, this.onCloseHandler);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.HeroArenaGetAllTeamInfo, this.onGetAllTeamsHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.HeroArenaGetAllTeamInfo, this.onGetAllTeamsHandler);
            return;
        }// end function

        private function updateInfoList() : void
        {
            var _loc_1:* = (this._pageSelecter.currentPage - 1) * 5;
            var _loc_2:* = this._pageSelecter.currentPage * 5;
            var _loc_3:* = Cache.instance.heroArena.allTeamInfo;
            var _loc_4:* = _loc_3.slice(_loc_1, _loc_2);
            var _loc_5:* = new DataProvider();
            _loc_5.addItems(_loc_4);
            this._infoList.dataProvider = _loc_5;
            this._infoList.drawNow();
            return;
        }// end function

        private function onGetAllTeamsHandler(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.heroArena.allTeamInfo;
            var _loc_3:* = Math.ceil(_loc_2.length / 5);
            this._pageSelecter.maxPage = _loc_3;
            this.updateInfoList();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateInfoList();
            return;
        }// end function

        private function onRefreshHandler(event:MouseEvent) : void
        {
            GameProxy.copy.getArenaTeamAll(0);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            GameProxy.copy.getArenaTeamAll(0);
            return;
        }// end function

        private function onCloseHandler(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._refreshBtn.dispose();
            this._refreshBtn = null;
            this._pageSelecter.dispose();
            this._pageSelecter = null;
            this._closeWinBtn.dispose();
            this._closeWinBtn = null;
            this._infoList.dispose();
            this._infoList = null;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : HeroArenaTeamGroupWin
        {
            if (_instance == null)
            {
                _instance = new HeroArenaTeamGroupWin;
            }
            return _instance;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
